import {
    takeEvery,
    takeLatest
} from 'redux-saga';
import {
    call,
    put
} from 'redux-saga/effects';

import {
    handleActions,
    createAction
} from 'redux-actions';

// root saga

var namespace = 'home';
var initState = {
    list: [],
    user: {
        name: '',
        age: ''
    },
}

export default {

    effects: {
        showPostsAsync: function* (action) {
            console.log('执行我了')
            console.log(action)
            console.log('啦啦啦')
            console.log(this)
        }
    },
    reducer: {
        [namespace]: handleActions({

            // 修改基础数据
            [namespace + '/setState']: {
                //成功执行的函数
                next(state, action) {

                    console.log('执行reducer')
                    return {
                        ...state,
                        ...action.payload,
                    };
                },
                //失败后执行的函数
                throw(state, action) {
                    return {
                        ...state
                    };
                }
            },
        }, initState),

    },
    watchGetPosts: function* () {
        yield takeLatest(namespace + '/showPostsAsync', this.effects.showPostsAsync);
    }
}